import { xqykjzz } from '../data/xqykjzz.js'
// 资产负债表
function balance(sheetData) {
  let balance = sheetData.filter(item => {
    if (item.reportItemRowNbr > 0) return item;
  });
  let balanceVK = xqykjzz.balance;
  balance.sort((a, b) => { return a.reportItemRowNbr - b.reportItemRowNbr })
  for (const key in balanceVK) {
    if (Object.hasOwnProperty.call(balanceVK, key)) {
      let input1 = $(`#${key}_qms`);
      let input2 = $(`#${key}_ncs`);
      let qmsNum = parseInt(key.split('_')[1])
      if (qmsNum === 15 || qmsNum === 29 || qmsNum === 30 || qmsNum === 41 || qmsNum === 46 || qmsNum === 47 || qmsNum === 52 || qmsNum === 53) {
        continue;
      }
      qmsNum < 10 ?
        document.form1.elements[`qms_0${parseInt(key.split('_')[1])}`].focus() :
        document.form1.elements[`qms_${parseInt(key.split('_')[1])}`].focus()
      input1.val(balance[parseInt(key.split('_')[1]) - 1].colValue1 || 0)
      qmsNum < 10 ?
        document.form1.elements[`ncs_0${parseInt(key.split('_')[1])}`].select() :
        document.form1.elements[`ncs_${parseInt(key.split('_')[1])}`].select()
      input2.val(balance[parseInt(key.split('_')[1]) - 1].colValue2 || 0);
    }
  }
}

// 利润表
function profit(sheetData, lastYearData, isSnlj) {
  let profit = sheetData.filter(item => {
    return item.reportItemRowNbr > 0
  })
  let lastYearProfit = lastYearData.filter(item => {
    return item.reportItemRowNbr > 0
  })
  let profitVK = xqykjzz.profit;
  profit.sort((a, b) => { return a.reportItemRowNbr - b.reportItemRowNbr });
  lastYearProfit.sort((a, b) => { return a.reportItemRowNbr - b.reportItemRowNbr });
  for (const key in profitVK) {
    if (Object.hasOwnProperty.call(profitVK, key)) {
      let input1 = $(`#${key}_bns`);
      let input2 = $(`#${key}_sns`);
      let bnsNum = parseInt(key.split('_')[1])
      if (bnsNum === 30 || bnsNum === 32 || bnsNum === 21) {
        continue;
      }
      bnsNum < 10 ?
        document.form1.elements[`bns_0${parseInt(key.split('_')[1])}`].focus() :
        document.form1.elements[`bns_${parseInt(key.split('_')[1])}`].focus()
      input1.val(profit[parseInt(key.split('_')[1]) - 1].colValue1 || 0)
      bnsNum < 10 ?
        document.form1.elements[`sns_0${parseInt(key.split('_')[1])}`].select() :
        document.form1.elements[`sns_${parseInt(key.split('_')[1])}`].select()
      if (isSnlj) {
        input2.val(lastYearProfit[parseInt(key.split('_')[1]) - 1].colValue1 || 0);
      }
    }
  }

}


// 现金流量表
function cash(sheetData, lastYearData, isSnlj) {
  let cash = sheetData.filter(item => {
    return item.reportItemRowNbr > 0
  })
  let lastYearCash = lastYearData.filter(item => {
    return item.reportItemRowNbr > 0
  })
  let cashVK = xqykjzz.cash;
  cash.sort((a, b) => { return a.reportItemRowNbr - b.reportItemRowNbr });
  lastYearCash.sort((a, b) => { return a.reportItemRowNbr - b.reportItemRowNbr });
  for (const key in cashVK) {
    if (Object.hasOwnProperty.call(cashVK, key)) {
      let input1 = $(`#${key}_bys`);
      let input2 = $(`#${key}_sys`);
      let bysNum = parseInt(key.split('_')[1])
      if (bysNum === 7 || bysNum === 13 || bysNum === 19 || bysNum === 20 || bysNum === 22) {
        continue;
      }
      bysNum < 10 ?
        document.form1.elements[`bys_0${parseInt(key.split('_')[1])}`].focus() :
        document.form1.elements[`bys_${parseInt(key.split('_')[1])}`].focus()
      input1.val(cash[parseInt(key.split('_')[1]) - 1].colValue1 || 0)
      bysNum < 10 ?
        document.form1.elements[`sys_0${parseInt(key.split('_')[1])}`].select() :
        document.form1.elements[`sys_${parseInt(key.split('_')[1])}`].select()
      if (isSnlj) input2.val(lastYearCash[parseInt(key.split('_')[1]) - 1].colValue1 || 0);
    }
  }

}

export {
  balance,
  cash,
  profit
}